  <div style="float:right">
    当前位置:<%=session["navigation"]%>
  </div>
  <br/>
  <br/>
<div id="tables">
  共有  <b><%= @dine.tables.size.to_s%></b>  张餐桌:
  <%=link_to_remote "点击查看详情" + image_tag("blank.png",:title => "点击查看概要",:class=>"about_item"),:update=>"show_tables",:url=>{:controller=>"tables",:action=>"query_tables",:id=>@dine.id},:complete=>"jQuery('#show_tables').show('fold')"%>
  已分配<%=@dine.eaters.size%>人，尚有<%=@dine.event.users.size - @dine.eaters.size%>人未分配
  <br/><p/>
  <br/>
  <li>主桌有
  <b><%=@dine.top_tables.size%></b> 
  张,
  共有<%=@top_table_users.size%>人就餐。
  <%=link_to_remote "点击查看详情" + image_tag("blank.png",:title => "点击查看概要",:class=>"about_item"),:update=>"show_tables",:url=>{:controller=>"tables",:action=>"query_tables",:id=>"#{@dine.id},TopTable"},:complete=>"jQuery('#show_tables').show('fold')"%>
  </li>
  <br/>
  <li>附桌有
  <b><%=@dine.normal_tables.size%></b>
  张,共有<%=@normal_table_users.size%> 人就餐。
  <%=link_to_remote "点击查看详情" + image_tag("blank.png",:title => "点击查看概要",:class=>"about_item"),:update=>"show_tables",:url=>{:controller=>"tables",:action=>"query_tables",:id=>"#{@dine.id},NormalTable"},:complete=>"jQuery('#show_tables').show('fold')"%>
  </li>
  <br/>
  <br/>
  <div id="show_tables">
  </div>
  <br/>
  <hr/>
  <br/>
  <div style="float:right">
    <a href="#" onclick="Element.toggle('new_table_form');return false">添加餐桌</a>  |
    <a href="#" onclick="Element.toggle('auto_allocation');return false">自动分配</a>  |
    <%=link_to '手动分配',event_dine_top_tables_path(:event_id=>@event.id,:dine_id=>@dine.id)%>  |
    <%=link_to "返回宴请",event_dines_path(:event_id=>@event.id)%>
  </div>
  <br />
  <br />


  <!--添加餐桌-->
  <div id="new_table_form" style='display:none'>
    <%remote_form_for :table,:url=>{:controller=>'tables',:action=>'create',:dine_id=>"#{@dine.id}"},:html=>{:id=>'table_form'} do |f|%>
        <div id="errors" style="display:none">
        </div>
        <br/>
        <div class="fields text_fields">
          <%= f.label :name,"餐桌号" %><%= f.text_field :name %><br clear="all"/>
        </div>
        <div class="fields select_fields">
          <%= f.label :type,'餐桌类型:' %><%=f.collection_select :type,Table::OPTIONS,:id,:name%><br clear="all"/>
        </div>
        <div class="buttons">
        <div class="lt_button">
          <%= f.submit '保存餐桌信息',:class=>'submit'%>
        </div>
      </div>
    <%end%>
  </div>

  <!--自动分配餐桌-->
  <div id="auto_allocation" style='display:none'>
    <li>第一步，<a href="#" onclick="Element.toggle('top_table_allocation');return false">分配主桌</a></li>
    <div id="top_table_allocation" style='display:none'>
      <%remote_form_for :table,:url=>{:controller=>'tables',:action=>'pre_top_table_allocation',:dine_id=>@dine.id} do |f|%>
      如果每个餐桌坐<%= f.select(:count,%w{1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20}) %>人,
      假设将其分配给
      <%= f.select(:start_level,Level::OPTIONS) %>
      和
      <%= f.select(:end_level,Level::OPTIONS) %>
      级别之间的人,
      <%= f.submit '那么' %>
      <%end%>
      <span id="table_top_table_place"></span>
    </div>
    <li>第二步，<a href="#" onclick="Element.toggle('normal_table_allocation');return false">分配附桌</a></li>
    <div id="normal_table_allocation" style='display:none'>
      <%if @user_hash.keys.size>0 %>
        <div id="pending_allocation_tables">
          <%@dine.normal_tables.each do |table|%>
            <fieldset id="pending_allocation_table_<%=table.id%>">
              <legend><%=table.name%></legend>
              <ul id="completed_table_<%=table.id%>">
                <% if table.froms
                      table.froms.split(',').each do |from|
                %>
                        <%=render :partial=>'completed_allocation_item',:locals=>{:id=>table.id,:key=>from,:user_hash=>@user_hash}%>
                <%
                      end
                    end%>
              </ul>
            </fieldset>
            <%=drop_receiving_element("pending_allocation_table_#{table.id}",:accept=>'.pending_allocation',:with=>"'from='+ encodeURIComponent(($(ui.draggable).attr('id')).split('_').last()) + ';current_table=' + #{table.id}+ ';table=' + encodeURIComponent(($(ui.draggable).attr('id')).split('_').first())",:url=>{:action=>'allocation_from_to_table'})%>
          <%end%>
        </div>
        <fieldset id="pending_allocation_user_groups">
          <legend>待分配项</legend>
          <ul id="pending_froms">
          <%@user_hash.keys.each do |key|%>
            <%unless @normal_table_froms.index(key)%>
              <%=render :partial=>'pending_allocation_item',:locals=>{:key=>key,:user_hash=>@user_hash}%>
            <%end%>
          <%end%>
          </ul>
        </fieldset>
        <%=drop_receiving_element('pending_allocation_user_groups',:accept=>'.pending_allocation',:with=>"'from='+ encodeURIComponent(($(ui.draggable).attr('id')).split('_').last()) + ';table=' + encodeURIComponent(($(ui.draggable).attr('id')).split('_').first())",:url=>{:action=>'allocation_table_to_from'})%>
      <%end%>
      <br/>
      <div style="float:right">
        <%=link_to "实施该方案",:action=>'allocation_normal_table',:id=>@dine.id%>
      </div>
    </div>
  </div>
</div>